<?php
include_once "../main.php";
include_once "../conn.php";

$uname = $_GET['uname'];
$ename = $_SESSION['ename'];

// 
// Start retrive data from database
//
$q1 = "SELECT * FROM job_view WHERE uname = '$uname' AND ename = '$ename' ";
$r1 = mysql_query($q1) or die(mysql_error());
$a1 = mysql_fetch_array($r1);

if (mysql_num_rows($r1) == '0'){

$q1 = "INSERT INTO job_view set
			 ename = \"$_SESSION[ename]\",
			 uname = \"$uname\" ";
$r1 = mysql_query($q1) or die(mysql_error());

$q2 = "SELECT * FROM job_employer_info WHERE ename = '$ename'";
$r2 = mysql_query($q2) or die(mysql_error());
$a2 = mysql_fetch_array($r2);

$q3 = "SELECT * FROM job_seeker_info WHERE uname = '$uname'";
$r3 = mysql_query($q3) or die(mysql_error());
$a3 = mysql_fetch_array($r3);

//
// Create subject and message body to send email
//
$sub   = "Request for your application from $a2[CompanyName]";
$msg   = "Hi $a3[fname] $a3[lname],

$a2[CompanyName] has requested to view your searchable resume and is 
interested in having you apply for the position provided by $a2[CompanyName].

If you are interested in this position, please send approval 
(http://$_SERVER[HTTP_HOST]$dir/employers/reply.php?&ename=$a2[ename]&uname=$a3[uname]&s=y) 
to $a2[CompanyName] to view your resume. The chance of obtaining an interview\n
will be higher since the company has already pre-qualified you. 

However, if you are NOT interested in the position, please reject 
(http://$_SERVER[HTTP_HOST]$dir/employers/reply.php?&ename=$a2[ename]&uname=$a3[uname]&s=n) 
the request within 1 week.

All the best and thank you.

From $sitename
";

//
// Start send email
//
$headers = "MIME-Version: 1.0\n"; 
$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
$headers .= "Content-Transfer-Encoding: 8bit\n"; 
$headers .= "From: $_SERVER[HTTP_HOST] <$aset[ContactEmail]>\n"; 
$headers .= "X-Priority: 1\n"; 
$headers .= "X-MSMail-Priority: High\n"; 
$headers .= "X-Mailer: PHP/" . phpversion()."\n";

$to = $a3['job_seeker_email'];
$subject = $sub;
$message_body = $msg; 
$b = @mail($to, $subject, $message_body, $headers);
$mesg = ($b) ? 'Request sent to  ' : 'Fail sending request to ';
echo "<br><br>";
echo $mesg.$a3['uname'].' ('.$to.')';	

}

else{

// 
// check overriding data in table job_view
//
$q1 = "SELECT * FROM job_seeker_info WHERE uname = '$uname'";
$r1 = mysql_query($q1) or die(mysql_error());
$a1 = mysql_fetch_array($r1);

echo "<br><br>You have already send request to view $a1[fname] $a1[lname] resume.";
echo "<br>Thank You.";
}
?>


